//
// Created by tyler on 4/10/17.
//

#include "quadrature/QuadratureRule.hpp"

YAFEL_NAMESPACE_OPEN

void QuadratureRule::get_triangle_quadrature(int porder)
{
    switch (porder) {
        case 1:
            nodes = {{1. / 3., 1. / 3.}
            };
            weights = {1. / 2.};
            return;
        case 2:
            nodes = {{1. / 6., 1. / 6.},
                     {1. / 6., 2. / 3.},
                     {2. / 3., 1. / 6.}};
            weights = {1. / 6., 1. / 6., 1. / 6.};
            return;
        case 3:
            nodes = {{3.33333333333333333E-01, 3.33333333333333333E-01},
                     {6.00000000000000000E-01, 2.00000000000000000E-01},
                     {2.00000000000000000E-01, 6.00000000000000000E-01},
                     {2.00000000000000000E-01, 2.00000000000000000E-01}};
            weights = {-2.81250000000000000E-01,
                       2.60416666666666667E-01,
                       2.60416666666666667E-01,
                       2.60416666666666666E-01};
            return;
        case 4:
            nodes = {{1.081030181680700E-01, 4.459484909159650E-01},
                     {4.459484909159650E-01, 1.081030181680700E-01},
                     {4.459484909159650E-01, 4.459484909159650E-01},
                     {8.168475729804590E-01, 9.157621350977100E-02},
                     {9.157621350977100E-02, 8.168475729804590E-01},
                     {9.157621350977100E-02, 9.157621350977100E-02}};
            weights = {1.116907948390055E-01,
                       1.116907948390055E-01,
                       1.116907948390055E-01,
                       5.497587182766100E-02,
                       5.497587182766100E-02,
                       5.497587182766100E-02};
            return;
        case 5:
            nodes = {{3.33333333333333E-01, 3.33333333333333E-01},
                     {5.97158717897700E-02, 4.70142064105115E-01},
                     {4.70142064105115E-01, 5.97158717897700E-02},
                     {4.70142064105115E-01, 4.70142064105115E-01},
                     {7.97426985353087E-01, 1.01286507323456E-01},
                     {1.01286507323456E-01, 7.97426985353087E-01},
                     {1.01286507323456E-01, 1.01286507323456E-01}};
            weights = {1.12500000000000E-01,
                       6.61970763942530E-02,
                       6.61970763942530E-02,
                       6.61970763942530E-02,
                       6.29695902724135E-02,
                       6.29695902724135E-02,
                       6.29695902724135E-02};
            return;
        case 6:
            nodes = {{5.01426509658179E-01, 2.49286745170910E-01},
                     {2.49286745170910E-01, 5.01426509658179E-01},
                     {2.49286745170910E-01, 2.49286745170910E-01},
                     {8.73821971016996E-01, 6.30890144915020E-02},
                     {6.30890144915020E-02, 8.73821971016996E-01},
                     {6.30890144915020E-02, 6.30890144915020E-02},
                     {5.31450498448170E-02, 3.10352451033784E-01},
                     {6.36502499121399E-01, 5.31450498448170E-02},
                     {3.10352451033784E-01, 6.36502499121399E-01},
                     {5.31450498448170E-02, 6.36502499121399E-01},
                     {6.36502499121399E-01, 3.10352451033784E-01},
                     {3.10352451033784E-01, 5.31450498448170E-02}};

            weights = {
                    5.83931378631895E-02, 5.83931378631895E-02,
                    5.83931378631895E-02, 2.54224531851035E-02,
                    2.54224531851035E-02, 2.54224531851035E-02,
                    4.14255378091870E-02, 4.14255378091870E-02,
                    4.14255378091870E-02, 4.14255378091870E-02,
                    4.14255378091870E-02, 4.14255378091870E-02
            };
            return;
        case 7:
            nodes = {{3.33333333333333E-01, 3.33333333333333E-01},
                     {4.79308067841920E-01, 2.60345966079040E-01},
                     {2.60345966079040E-01, 4.79308067841920E-01},
                     {2.60345966079040E-01, 2.60345966079040E-01},
                     {8.69739794195568E-01, 6.51301029022160E-02},
                     {6.51301029022160E-02, 8.69739794195568E-01},
                     {6.51301029022160E-02, 6.51301029022160E-02},
                     {4.86903154253160E-02, 3.12865496004874E-01},
                     {6.38444188569810E-01, 4.86903154253160E-02},
                     {3.12865496004874E-01, 6.38444188569810E-01},
                     {4.86903154253160E-02, 6.38444188569810E-01},
                     {6.38444188569810E-01, 3.12865496004874E-01},
                     {3.12865496004874E-01, 4.86903154253160E-02}};

            weights = {-7.47850222338410E-02, 8.78076287166040E-02,
                       8.78076287166040E-02, 8.78076287166040E-02,
                       2.66736178044190E-02, 2.66736178044190E-02,
                       2.66736178044190E-02, 3.85568804451285E-02,
                       3.85568804451285E-02, 3.85568804451285E-02,
                       3.85568804451285E-02, 3.85568804451285E-02,
                       3.85568804451285E-02};
            return;

        case 8:

            nodes = {
                    {3.33333333333333E-01, 3.33333333333333E-01},
                    {8.14148234145540E-02, 4.59292588292723E-01},
                    {4.59292588292723E-01, 8.14148234145540E-02},
                    {4.59292588292723E-01, 4.59292588292723E-01},
                    {6.58861384496480E-01, 1.70569307751760E-01},
                    {1.70569307751760E-01, 6.58861384496480E-01},
                    {1.70569307751760E-01, 1.70569307751760E-01},
                    {8.98905543365938E-01, 5.05472283170310E-02},
                    {5.05472283170310E-02, 8.98905543365938E-01},
                    {5.05472283170310E-02, 5.05472283170310E-02},
                    {8.39477740995800E-03, 2.63112829634638E-01},
                    {7.28492392955404E-01, 8.39477740995800E-03},
                    {2.63112829634638E-01, 7.28492392955404E-01},
                    {8.39477740995800E-03, 7.28492392955404E-01},
                    {7.28492392955404E-01, 2.63112829634638E-01},
                    {2.63112829634638E-01, 8.39477740995800E-03}};

            weights = {7.21578038388935E-02, 4.75458171336425E-02,
                       4.75458171336425E-02, 4.75458171336425E-02,
                       5.16086852673590E-02, 5.16086852673590E-02,
                       5.16086852673590E-02, 1.62292488115990E-02,
                       1.62292488115990E-02, 1.62292488115990E-02,
                       1.36151570872175E-02, 1.36151570872175E-02,
                       1.36151570872175E-02, 1.36151570872175E-02,
                       1.36151570872175E-02, 1.36151570872175E-02};
            return;

        case 9:
            nodes = {{3.33333333333333E-01, 3.33333333333333E-01},
                     {2.06349616025250E-02, 4.89682519198738E-01},
                     {4.89682519198738E-01, 2.06349616025250E-02},
                     {4.89682519198738E-01, 4.89682519198738E-01},
                     {1.25820817014127E-01, 4.37089591492937E-01},
                     {4.37089591492937E-01, 1.25820817014127E-01},
                     {4.37089591492937E-01, 4.37089591492937E-01},
                     {6.23592928761935E-01, 1.88203535619033E-01},
                     {1.88203535619033E-01, 6.23592928761935E-01},
                     {1.88203535619033E-01, 1.88203535619033E-01},
                     {9.10540973211095E-01, 4.47295133944530E-02},
                     {4.47295133944530E-02, 9.10540973211095E-01},
                     {4.47295133944530E-02, 4.47295133944530E-02},
                     {3.68384120547360E-02, 2.21962989160766E-01},
                     {7.41198598784498E-01, 3.68384120547360E-02},
                     {2.21962989160766E-01, 7.41198598784498E-01},
                     {3.68384120547360E-02, 7.41198598784498E-01},
                     {7.41198598784498E-01, 2.21962989160766E-01},
                     {2.21962989160766E-01, 3.68384120547360E-0}};

            weights = {4.85678981413995E-02, 1.56673501135695E-02,
                       1.56673501135695E-02, 1.56673501135695E-02,
                       3.89137705023870E-02, 3.89137705023870E-02,
                       3.89137705023870E-02, 3.98238694636050E-02,
                       3.98238694636050E-02, 3.98238694636050E-02,
                       1.27888378293490E-02, 1.27888378293490E-02,
                       1.27888378293490E-02, 2.16417696886445E-02,
                       2.16417696886445E-02, 2.16417696886445E-02,
                       2.16417696886445E-02, 2.16417696886445E-02,
                       2.16417696886445E-02};

            return;

        case 10:
            nodes = {{3.33333333333333E-01, 3.33333333333333E-01},
                     {2.88447332326850E-02, 4.85577633383657E-01},
                     {4.85577633383657E-01, 2.88447332326850E-02},
                     {4.85577633383657E-01, 4.85577633383657E-01},
                     {7.81036849029926E-01, 1.09481575485037E-01},
                     {1.09481575485037E-01, 7.81036849029926E-01},
                     {1.09481575485037E-01, 1.09481575485037E-01},
                     {1.41707219414880E-01, 3.07939838764121E-01},
                     {5.50352941820999E-01, 1.41707219414880E-01},
                     {3.07939838764121E-01, 5.50352941820999E-01},
                     {1.41707219414880E-01, 5.50352941820999E-01},
                     {5.50352941820999E-01, 3.07939838764121E-01},
                     {3.07939838764121E-01, 1.41707219414880E-01},
                     {2.50035347626860E-02, 2.46672560639903E-01},
                     {7.28323904597411E-01, 2.50035347626860E-02},
                     {2.46672560639903E-01, 7.28323904597411E-01},
                     {2.50035347626860E-02, 7.28323904597411E-01},
                     {7.28323904597411E-01, 2.46672560639903E-01},
                     {2.46672560639903E-01, 2.50035347626860E-02},
                     {9.54081540029900E-03, 6.68032510122000E-02},
                     {9.23655933587500E-01, 9.54081540029900E-03},
                     {6.68032510122000E-02, 9.23655933587500E-01},
                     {9.54081540029900E-03, 9.23655933587500E-01},
                     {9.23655933587500E-01, 6.68032510122000E-02},
                     {6.68032510122000E-02, 9.54081540029900E-03}};

            weights = {4.54089951913770E-02, 1.83629788782335E-02,
                       1.83629788782335E-02, 1.83629788782335E-02,
                       2.26605297177640E-02, 2.26605297177640E-02,
                       2.26605297177640E-02, 3.63789584227100E-02,
                       3.63789584227100E-02, 3.63789584227100E-02,
                       3.63789584227100E-02, 3.63789584227100E-02,
                       3.63789584227100E-02, 1.41636212655285E-02,
                       1.41636212655285E-02, 1.41636212655285E-02,
                       1.41636212655285E-02, 1.41636212655285E-02,
                       1.41636212655285E-02, 4.71083348186650E-03,
                       4.71083348186650E-03, 4.71083348186650E-03,
                       4.71083348186650E-03, 4.71083348186650E-03,
                       4.71083348186650E-03};
            return;
        default:
            throw std::runtime_error("Error: Unsupported triangle quadrature polyOrder: " + std::to_string(porder));
    }

}


YAFEL_NAMESPACE_CLOSE